const redis = require('redis');
const { redis: redisOptions } = require("../config/conifg")
const client = redis.createClient(redisOptions.db);
client.on("connect", function () {
    console.log("redis链接成功！")
})
client.on("error", function (error) {
    console.error(error);
});
module.exports = {
    client,
    set: client.set,
    get: client.get,
    rpush: (...args) => {
        return new Promise((resolve, reject) => {
            client.send_command('rpush', [redisOptions.nameSpace + '-' + args.splice(0, 1), ...args], function (err, data) {
                if (err) {
                    reject(err)
                } else {
                    resolve(data)
                }
            })
        })
    },
    lpop: client.lpop,
    lrange: (...args) => {
        return new Promise((resolve, reject) => {
            client.lrange(redisOptions.nameSpace + '-' + args.splice(0, 1), ...args, (err,data) => {
                if (err) {
                    reject(err)
                } else {
                    resolve(data)
                }
            })
        })

    }
}